package iterator;

/**
 * @author wcj
 * @Date 2021/7/4 20:29
 * @Version 1.0
 */
public class ConcreteIterator extends Iterator {

    public ConcreteAggregate aggregate;
    int current = 0;

    public ConcreteIterator(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;
    }

    @Override
    public Object first() {
        return aggregate.index(0);
    }

    @Override
    public Object next() {
        Object obj = null;
        if (current < aggregate.count()) {
            return aggregate.index(current);
        }
        return obj;
    }

    @Override
    public boolean hasNext() {
        return current < aggregate.count();
    }

    @Override
    public Object current(int index) {
        return aggregate.index(index);
    }
}
